// 示例代码：测试反射能否获取泛型信息
package com.stu.reflection.generic;

import java.lang.reflect.Method;
import java.util.*;

public class TestGeneric {
  public Map<Integer, String> test(Map<Integer, String> map, List<String> list) { return null; }

  public static void main(String[] args) throws Exception {
    Method method = TestGeneric.class.getMethod("test", Map.class,List.class);
    // 无泛型信息
    System.out.println(method.getReturnType());
    System.out.println(Arrays.toString(method.getParameterTypes()));
    System.out.println("------------");
    // 有泛型信息
    System.out.println(method.getGenericReturnType());
    System.out.println(Arrays.toString(method.getGenericParameterTypes()));
    /*测试结果：
      interface java.util.Map
      [interface java.util.Map, interface java.util.List]
      ------------
      java.util.Map<java.lang.Integer, java.lang.String>
      [java.util.Map<java.lang.Integer, java.lang.String>, java.util.List<java.lang.String>]
    */
  }
}
